package com.seabook.store.purchase.domain;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.List;

import com.seabook.store.auth.domain.Address;

public class Order implements Serializable {
    
    private static final long serialVersionUID = 8622697585252594514L;

    public enum Status {
        INIT, NEW, UNPAID,  PAID, CONFIRMED , SHIPPING, RECEIVED, COMPLETED, CANCELED, EXPIRED
    };

    /* Private Fields */

    private int orderId;
    private int userId;
    private String username = "";
    private Date orderDate;
    private Date expireDate;
    private String shipAddress = "";
    private String shipAddress2 = "";
    private String shipPhone = "";
    private String shipEmail = "";
    private String shipCity = "";
    private String shipState = "";
    private String shipZip = "";
    private String shipSurburb = "";
    private String shipCountry = "";
    private String billAddress = "";
    private String billAddress2 = "";
    private String billCity = "";
    private String billState = "";
    private String billZip = "";
    private String billCountry = "";
    private String billSurburb = "";
    private String courier = "";
    private double subTotal;
    private double shippingFee;
    private double totalPrice;
    private String billToFirstName = "";
    private String billToLastName = "";
    private String shipToFirstName = "";
    private String shipToLastName = "";
    private Status status = Status.INIT;
    private String comment = "";
    private String payMethod = "";
    private String shippingMethod = "";
    private List<LineItem> lineItems = new ArrayList<LineItem>();

    /* JavaBeans Properties */

    public int getOrderId() {
        return orderId;
    }

    public void setOrderId(int orderId) {
        this.orderId = orderId;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public Date getOrderDate() {
        return orderDate;
    }

    public void setOrderDate(Date orderDate) {
        this.orderDate = orderDate;
    }

    public String getShipCity() {
        return shipCity;
    }

    public void setShipCity(String shipCity) {
        this.shipCity = shipCity;
    }

    public String getShipState() {
        return shipState;
    }

    public void setShipState(String shipState) {
        this.shipState = shipState;
    }

    public String getShipZip() {
        return shipZip;
    }

    public void setShipZip(String shipZip) {
        this.shipZip = shipZip;
    }

    public String getShipCountry() {
        return shipCountry;
    }

    public void setShipCountry(String shipCountry) {
        this.shipCountry = shipCountry;
    }

    public String getBillCity() {
        return billCity;
    }

    public void setBillCity(String billCity) {
        this.billCity = billCity;
    }

    public String getBillState() {
        return billState;
    }

    public void setBillState(String billState) {
        this.billState = billState;
    }

    public String getBillZip() {
        return billZip;
    }

    public void setBillZip(String billZip) {
        this.billZip = billZip;
    }

    public String getBillCountry() {
        return billCountry;
    }

    public void setBillCountry(String billCountry) {
        this.billCountry = billCountry;
    }

    public String getCourier() {
        return courier;
    }

    public void setCourier(String courier) {
        this.courier = courier;
    }

    public double getTotalPrice() {
        return totalPrice;
    }

    public void setTotalPrice(double totalPrice) {
        this.totalPrice = totalPrice;
    }

    public String getBillToFirstName() {
        return billToFirstName;
    }

    public void setBillToFirstName(String billToFirstName) {
        this.billToFirstName = billToFirstName;
    }

    public String getBillToLastName() {
        return billToLastName;
    }

    public void setBillToLastName(String billToLastName) {
        this.billToLastName = billToLastName;
    }

    public String getShipToFirstName() {
        return shipToFirstName;
    }

    public void setShipToFirstName(String shipFoFirstName) {
        this.shipToFirstName = shipFoFirstName;
    }

    public String getShipToLastName() {
        return shipToLastName;
    }

    public void setShipToLastName(String shipToLastName) {
        this.shipToLastName = shipToLastName;
    }

    public Status getStatus() {
        return status;
    }

    public void setStatus(Status status) {
        this.status = status;
    }

    public void setLineItems(List<LineItem> lineItems) {
        this.lineItems = lineItems;
    }

    public List<LineItem> getLineItems() {
        return lineItems;
    }

    /* Public Methods */

    public void initOrder(Address shippingAddress, Cart cart) {
        username = shippingAddress.getUserName();
        orderDate = new Date();

        shipToFirstName = shippingAddress.getFirstName();
        shipToLastName = shippingAddress.getLastName();
        shipAddress = shippingAddress.getAddress1();
        shipCity = shippingAddress.getCity();
        shipState = shippingAddress.getState();
        shipZip = shippingAddress.getPostcode();
        shipCountry = shippingAddress.getCountry();

        billToFirstName = shippingAddress.getFirstName();
        billToLastName = shippingAddress.getLastName();
        billAddress = shippingAddress.getAddress1();
        billCity = shippingAddress.getCity();
        billState = shippingAddress.getState();
        billZip = shippingAddress.getPostcode();
        billCountry = shippingAddress.getCountry();

        totalPrice = cart.getSubTotal();

        courier = "UPS";
        status = Status.NEW;

        Iterator<CartItem> i = cart.getAllCartItems();
        while (i.hasNext()) {
            CartItem cartItem = (CartItem) i.next();
            addLineItem(cartItem);
        }
    }

    public void addLineItem(CartItem cartItem) {
        LineItem lineItem = new LineItem(lineItems.size() + 1, cartItem);
        addLineItem(lineItem);
    }

    public void addLineItem(LineItem lineItem) {
        lineItems.add(lineItem);
    }

    public int getUserId() {
        return userId;
    }

    public void setUserId(int userId) {
        this.userId = userId;
    }

    public String getShipAddress() {
        return shipAddress;
    }

    public void setShipAddress(String shipAddress) {
        this.shipAddress = shipAddress;
    }

    public String getBillAddress() {
        return billAddress;
    }

    public void setBillAddress(String billAddress) {
        this.billAddress = billAddress;
    }

    public String getShipPhone() {
        return shipPhone;
    }

    public void setShipPhone(String shipPhone) {
        this.shipPhone = shipPhone;
    }

    public String getShipEmail() {
        return shipEmail;
    }

    public void setShipEmail(String shipEmail) {
        this.shipEmail = shipEmail;
    }

    public String getShipSurburb() {
        return shipSurburb;
    }

    public void setShipSurburb(String shipSurburb) {
        this.shipSurburb = shipSurburb;
    }

    public String getShipAddress2() {
        return shipAddress2;
    }

    public void setShipAddress2(String shipAddress2) {
        this.shipAddress2 = shipAddress2;
    }

    public String getComment() {
        return comment;
    }

    public void setComment(String comment) {
        this.comment = comment;
    }

    public double getSubTotal() {
        return subTotal;
    }

    public void setSubTotal(double subTotal) {
        this.subTotal = subTotal;
    }

    public double getShippingFee() {
        return shippingFee;
    }

    public void setShippingFee(double shippingFee) {
        this.shippingFee = shippingFee;
    }

    public String getPayMethod() {
        return payMethod;
    }

    public void setPayMethod(String payMethod) {
        this.payMethod = payMethod;
    }

    public String getShippingMethod() {
        return shippingMethod;
    }

    public void setShippingMethod(String shippingMethod) {
        this.shippingMethod = shippingMethod;
    }

    public String getBillAddress2() {
        return billAddress2;
    }

    public void setBillAddress2(String billAddress2) {
        this.billAddress2 = billAddress2;
    }

    public Date getExpireDate() {
        return expireDate;
    }

    public void setExpireDate(Date expireDate) {
        this.expireDate = expireDate;
    }

    public String getBillSurburb() {
        return billSurburb;
    }

    public void setBillSurburb(String billSurburb) {
        this.billSurburb = billSurburb;
    }

    public void setStatus(String string) {
        this.status = Enum.valueOf(Status.class,string);
    }

}
